package com.liu.tcpDemo.Client;

import com.alibaba.fastjson.JSONObject;

import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

//客户端向服务端发送数据的类
public class ClientSend implements Runnable{
    private Socket socket;
    private ObjectOutputStream oos;
    public ClientSend(Socket socket,ObjectOutputStream oos) {
        this.socket = socket;
        this.oos=oos;
    }

    @Override
    public void run() {
        try {
            Scanner scanner=new Scanner(System.in);
            while (true){
                JSONObject jsonObject=new JSONObject();
                jsonObject.put("chat",scanner.next());
                jsonObject.put("type","msg");
                oos.writeObject(jsonObject);
                oos.flush();
            }
        } catch (Exception e) {
            Connect.socketState=false;
            Connect.reConnnect();
        }
    }
}
